﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoBackupDatabase.DBConection;

namespace AutoBackupDatabase
{
    using System.Data;
    using System.Data.SqlClient;

    using AutoBackupDatabase.ENT;

    class EXPORTDETAILDAL
    {
         private DbConnection conn;
         public EXPORTDETAILDAL()
        {
            conn = new DbConnection();
        }

         public List<EXPORTDETAILENT> GETDETAILEXPORTBYTABLEID(int tableId)
         {
             string query = string.Format("exec GETDETAILEXPORTBYTABLEID "+tableId);
             DataTable ds = conn.executeGetQuery(query);
             List<EXPORTDETAILENT> List = new List<EXPORTDETAILENT>();
             try
             {

                 foreach (DataRow item in ds.Rows)
                 {
                     EXPORTDETAILENT exportdetailent = new EXPORTDETAILENT();
                     exportdetailent.ITEMID = int.Parse(item["ITEMID"].ToString());
                     exportdetailent.EXPORTID = item["EXPORTID"].ToString();
                     exportdetailent.QUANTITY = int.Parse(item["QUANTITY"].ToString());
                     exportdetailent.PRICE = float.Parse(item["PRICE"].ToString());
                     exportdetailent.ITEMDISCOUNT = float.Parse(item["ITEMDISCOUNT"].ToString());
                     exportdetailent.ISITEMPAY = bool.Parse(item["ISITEMPAY"].ToString());
                     exportdetailent.ITEMNAME = item["ITEMNAME"].ToString();
                     exportdetailent.TOTAL = double.Parse(item["TOTAL"].ToString());
                     exportdetailent.VAT = float.Parse(item["VAT"].ToString());
                     exportdetailent.SERVICE = float.Parse(item["SERVICE"].ToString());
                     exportdetailent.TABLEDISCOUNT = float.Parse(item["TABLEDISCOUNT"].ToString());


                     List.Add(exportdetailent);
                 }
                 return List;
             }
             catch (Exception)
             {

                 return List;
             }

         }
         public List<EXPORTDETAILENT> GETDETAILEXPORTBYEXPORTID(string exportId)
         {
             string query = string.Format("exec GETDETAILEXPORTBYEXPORTID " + exportId);
             DataTable ds = conn.executeGetQuery(query);
             List<EXPORTDETAILENT> List = new List<EXPORTDETAILENT>();
             try
             {

                 foreach (DataRow item in ds.Rows)
                 {
                     EXPORTDETAILENT exportdetailent = new EXPORTDETAILENT();
                     exportdetailent.ITEMID = int.Parse(item["ITEMID"].ToString());
                     exportdetailent.EXPORTID = item["EXPORTID"].ToString();
                     exportdetailent.QUANTITY = int.Parse(item["QUANTITY"].ToString());
                     exportdetailent.PRICE = float.Parse(item["PRICE"].ToString());
                     exportdetailent.ITEMDISCOUNT = float.Parse(item["ITEMDISCOUNT"].ToString());
                     exportdetailent.ISITEMPAY = bool.Parse(item["ISITEMPAY"].ToString());
                     exportdetailent.ITEMNAME = item["ITEMNAME"].ToString();
                     exportdetailent.TOTAL = double.Parse(item["TOTAL"].ToString());
                     exportdetailent.VAT = float.Parse(item["VAT"].ToString());
                     exportdetailent.SERVICE = float.Parse(item["SERVICE"].ToString());
                     exportdetailent.TABLEDISCOUNT = float.Parse(item["TABLEDISCOUNT"].ToString());


                     List.Add(exportdetailent);
                 }
                 return List;
             }
             catch (Exception)
             {

                 return List;
             }

         }

         public bool UPDATEDISCOUNTFORITEM(string exportID, int itemId, float itemDiscount)
         {
             string query = "exec  UPDATEDISCOUNTFORITEM @EXPORTID,@ITEMID,@ITEMDISCOUNT";
             SqlParameter[] sqlParameters = new SqlParameter[3];
             sqlParameters[0] = new SqlParameter("@EXPORTID", SqlDbType.VarChar);
             sqlParameters[0].Value = exportID;
             sqlParameters[1] = new SqlParameter("@ITEMID", SqlDbType.Int);
             sqlParameters[1].Value = itemId;
             sqlParameters[2] = new SqlParameter("@ITEMDISCOUNT", SqlDbType.Float);
             sqlParameters[2].Value = itemDiscount;
             return conn.executeUpdateQuery(query, sqlParameters);
         }
    }
}
